<template>
    <h1 style="text-align: center;">添加投资信息</h1>

    <table>
        <tr>
            <td>投资项目名称</td>
            <td>
                <input type="text"  v-model="Invest.I_Name">
            </td>
        </tr>

        <tr>
            <td>投资项目总金额</td>
            <td>
                <input type="text" v-model="Invest.I_Budget" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="添加" @click="AddInvest">
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">

import { ref } from 'vue';
import axios from 'axios';
//import { useRouter } from 'vue-router';

//const router = useRouter();

const Invest = ref({
    I_Name:'',
    I_Budget:'',
})

const AddInvest = ()=>{

    if(Invest.value.I_Name==""){
        alert('投资项目名称不能为空');
        return;
    }

    if(Invest.value.I_Budget==""){
        alert('投资项目总金额不能为空');
        return;
    }

    if( Number(Invest.value.I_Budget)<=0 || Number(Invest.value.I_Budget)>100000000 ){
        alert('投资项目总金额必须大于0且小于1亿元');
        return;
    }


    axios({
        method:'post',
        url:'http://localhost:63517/api/Invest/AddInvest',
        data:{
            I_Name:Invest.value.I_Name,
            I_Budget:Invest.value.I_Budget,
        }
    })
    .then(res=>{
        console.log(res.data);
        if(res.data>0){
            alert('添加成功');
        }
        else if(res.data==-1){
            alert('投资项目名称已存在');
            return;
        }
        else{
            alert('添加失败');
            return;
        }
    })
    .catch(err=>{
        console.log(err);
    })
}

</script>